<?php
/**
 * Description of fwiSimpleTemplate
 *
 * @author trunghpb
 */
class SimpleTemplate implements infTemplate {
    private $aryParams = array();
    private $templateFile = null;
    private $templatePath = null;
    private $buffer = null;

    public function set($name, $value) {
        $this->aryParams[$name] = $value;
    }

    public function get($name) {
        return $this->aryParams[$name];
    }


    public function compile() {
        if (file_exists($this->fullPath())){
            extract($this->aryParams, EXTR_OVERWRITE);
            ob_start();
            include_once $this->fullPath();
            $this->buffer = ob_get_contents();
            ob_end_clean();
            return $this->buffer;
        }else{
            throw new fwiException(102);
        }
    }

    public function getHtml() {
        return $this->buffer;
    }

    public function setFile($file) {
        $this->templateFile = $file;
    }

    public function setPath($path) {
        $this->templatePath = $path;
    }

    public function fullPath(){
        return trim($this->templatePath, "\\").DIRECTORY_SEPARATOR.$this->templateFile.'.php';
    }

    public function render() {
        if (file_exists($this->fullPath())){
            extract($this->aryParams, EXTR_OVERWRITE);
            include_once $this->fullPath();
        }else{
            throw new fwiException(102);
        }
    }
}
?>
